require("io")
pic_root="/Users/tzp/Pictures/pic"
function log(msg) 
    ngx.log(ngx.ERR, msg)
end

function scanpic(type, dic)
    local ptags = io.popen('ls "'..pic_root..type..'"')
    local tags = ptags:lines()
    for tagname in tags do
        if tagname:sub(1,1) ~= '.'
        then
            log(type..' tag: '..tagname)
            local i = 0
            local ptag = io.popen('ls "'..pic_root..type..tagname..'/"')
            local pics = ptag:lines()
            for picname in pics do
                if picname:sub(1,1) ~= '.'
                then
                    log(type..' pic: '..picname)
                    dic.add(dic, (tagname.."_"..i), picname, 0)
                    i = i + 1
                end
            end
        ptag:close()
            dic.add(dic, ("num_"..tagname), i, 0)
        end
    end
    ptags:close()
end

log("initing-pic_server-lua")
scanpic('/v/', ngx.shared.pics_v)
scanpic('/h/', ngx.shared.pics_h)